package com.orm;

import org.w3c.dom.Document;
import org.xml.sax.SAXException;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.io.IOException;

/**
 * 数据库的配置类
 *
 */
class DbConfiguration {
    public static final String CONFIGFILENAME="DbConfiguration.xml";
    public static String DriverName;
    public static String ConnectionString;


    static{
        String filePath = Thread.currentThread().getContextClassLoader().getResource("").getPath();
        File file = new File(filePath,CONFIGFILENAME);
        System.out.println("配置文件存储路径："+ file.getAbsolutePath());
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        if(file.exists())
        {
            try {
                Document document = dbf.newDocumentBuilder().parse(file);
                DriverName = document.getElementsByTagName("DriverName").item(0).getFirstChild().getNodeValue();
                ConnectionString = document.getElementsByTagName("ConnectionString").item(0).getFirstChild().getNodeValue();
            } catch (SAXException | IOException | ParserConfigurationException e) {
                e.printStackTrace();
            }
        }

    }
}
